package com.erp.shop.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.erp.shop.domain.ErpSellerStoreEmpowerAutoPush;
import com.erp.shop.domain.bo.ErpSellerStoreEmpowerAutoPushBo;
import com.erp.shop.domain.vo.ErpSellerStoreEmpowerAutoPushVo;
import com.erp.shop.service.IErpSellerStoreEmpowerAutoPushService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 店铺自动刊登配置
 *
 * @author erp
 * @date 2023-09-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/seller/sellerStoreEmpowerAutoPush")
public class ErpSellerStoreEmpowerAutoPushController extends BaseController {

    private final IErpSellerStoreEmpowerAutoPushService iErpSellerStoreEmpowerAutoPushService;

    /**
     * 查询店铺自动刊登配置列表
     */
    @SaCheckPermission("seller:sellerStoreEmpowerAutoPush:list")
    @GetMapping("/list")
    public TableDataInfo<ErpSellerStoreEmpowerAutoPushVo> list(ErpSellerStoreEmpowerAutoPushBo bo, PageQuery pageQuery) {
        return iErpSellerStoreEmpowerAutoPushService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出店铺自动刊登配置列表
     */
    @SaCheckPermission("seller:sellerStoreEmpowerAutoPush:export")
    @Log(title = "店铺自动刊登配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ErpSellerStoreEmpowerAutoPushBo bo, HttpServletResponse response) {
        List<ErpSellerStoreEmpowerAutoPushVo> list = iErpSellerStoreEmpowerAutoPushService.queryList(bo);
        ExcelUtil<ErpSellerStoreEmpowerAutoPushVo> excelUtil = new ExcelUtil<>(ErpSellerStoreEmpowerAutoPushVo.class);
        excelUtil.exportExcel(response,list,"店铺自动刊登配置");
//        ExcelUtil.exportExcel(list, "店铺自动刊登配置", ErpSellerStoreEmpowerAutoPushVo.class, response);
    }

    /**
     * 获取店铺自动刊登配置详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("seller:sellerStoreEmpowerAutoPush:query")
    @GetMapping("/{id}")
    public R<ErpSellerStoreEmpowerAutoPushVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpSellerStoreEmpowerAutoPushService.queryById(id));
    }

    /**
     * 新增店铺自动刊登配置
     */
    @SaCheckPermission("seller:sellerStoreEmpowerAutoPush:add")
    @Log(title = "店铺自动刊登配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerStoreEmpowerAutoPushBo bo) {
        return toAjax(iErpSellerStoreEmpowerAutoPushService.insertByBo(bo));
    }

    /**
     * 修改店铺自动刊登配置
     */
    @SaCheckPermission("seller:sellerStoreEmpowerAutoPush:edit")
    @Log(title = "店铺自动刊登配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerStoreEmpowerAutoPushBo bo) {
        return toAjax(iErpSellerStoreEmpowerAutoPushService.updateByBo(bo));
    }

    /**
     * 删除店铺自动刊登配置
     *
     * @param ids 主键串
     */
    @SaCheckPermission("seller:sellerStoreEmpowerAutoPush:remove")
    @Log(title = "店铺自动刊登配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSellerStoreEmpowerAutoPushService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
